<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" :title="'注册'" width="850px">
    <el-form ref="form" :model="form" :rules="formRules" size="small" label-width="100px">
     <el-card>
      <div slot="header">
        <span>商家信息</span>
      </div>
    <el-col :span="12">
      <el-form-item label="手机" prop="phone" required>
        <el-input v-model="form.phone"  style="width: 250px;" />
      </el-form-item>
      <el-form-item label="邮箱" prop="email" required>
        <el-input v-model="form.email"  style="width: 250px;" />
      </el-form-item>
       <el-form-item label="联系人姓名" prop="conName" required>
        <el-input v-model="form.conName" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="联系人手机" prop="conMobile" required>
        <el-input v-model="form.conMobile" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="联系人qq">
        <el-input v-model="form.conQq" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="联系人email" >
        <el-input v-model="form.conEmail" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="法定代表人身份证号"  prop="legalIndentity" required >
        <el-input v-model="form.legalIndentity" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="开户行名称" prop="openBank"  required>
        <el-input v-model="form.openBank" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="开户行支行"  prop="obBranch" required>
        <el-input v-model="form.obBranch" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="商家状态"  prop="status" required>
        <el-radio-group v-model="form.status">
        <el-radio label="0">待审核</el-radio>
        <el-radio label="1">已审核</el-radio>
        </el-radio-group>
      </el-form-item>
      </el-col>
        <el-col :span="12">
         <el-form-item label="公司名称" prop="compName" required>
        <el-input v-model="form.compName" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="公司手机">
        <el-input v-model="form.compMobile" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="公司电话" >
        <el-input v-model="form.compPhone" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="公司地址"  prop="compAddress" required>
        <el-input v-model="form.compAddress" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="营业执照号" prop="licenseNum" required>
        <el-input v-model="form.licenseNum" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="税务登记号">
        <el-input v-model="form.taxRegistNum" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="组织机构代码证">
        <el-input v-model="form.organNum" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="法定代表人" prop="legal" required>
        <el-input v-model="form.legal" style="width: 250px;" />
      </el-form-item>
       <el-form-item label="银行账号" prop="bankNum" required>
        <el-input v-model="form.bankNum" style="width: 250px;" />
      </el-form-item>
      </el-col>
     </el-card>

     <el-card>
      <div slot="header">
        <span>店铺信息</span>
      </div>
        <el-form-item label="店铺名称" :rules="{ required: true,trigger: 'blur' }" required>
        <el-input v-model="form.tbShop.shopName"  style="width: 250px;" />
      </el-form-item>
     </el-card>

     <el-card>
      <div slot="header">
        <span>登录信息</span>
      </div>
        <el-col :span="12">
      <el-form-item label="登录名"  :rules="{ required: true,trigger: 'blur' }" required>
        <el-input v-model="form.tbUser.userName" style="width: 250px;" />
      </el-form-item>
      <el-form-item label="登录密码" :rules="{ required: true,trigger: 'blur' }" required>
        <el-input v-model="form.tbUser.userPassword" style="width: 250px;" type="password"/>
      </el-form-item>
      </el-col>
     </el-card>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {register,compNameExist} from '@/api/login.js'
import { validatePhone,validEmail } from '@/utils/validate'
export default {
  data() {
    return {
      loading: false, dialog: false,
      form: {
         businessId:'',
        phone: '',
        email: '',
        conName: '',
        conMobile: '',
        conQq: '',
        conEmail: '',
        legalIndentity: '',
        openBank: '',
        obBranch: '',
        status: '',
        compName: '',
        compMobile: '',
        compPhone: '',
        compAddress: '',
        licenseNum: '',
        taxRegistNum: '',
        organNum: '',
        legal: '',
        bankNum: '',
        tbShop:{
            shopName: ''
        },
        tbUser:{
            userName: '',
            userPassword: ''
        }
        
      },
      uname: '',
      formRules: {
        phone: [ { required: true, message: 'please enter', trigger: 'blur' },
           { validator: validatePhone, trigger: 'blur' }],
        email: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        conName: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        conMobile: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        legalIndentity: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        openBank: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        obBranch: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        compName: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        compAddress: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        licenseNum: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        legal: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ],
        bankNum: [
          { required: true, message: 'please enter', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
        this.register()
    },
    register() {
        this.$refs['form'].validate((valid) => {
        if (valid) {
            register(this.form).then(res => {
                if(res.message=="success"){
                this.resetForm()
                 this.$notify({
                title: '添加成功',
                type: 'success',
                duration: 2500})
                this.loading = false
            this.$parent.init()
                }else{
            this.$message.error(res.message)
                }

            }).catch(err => {
                this.loading = false
                console.log(err.response.data.message)
            })
    } else {
          return false
        }
          })
        } ,
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        phone: '',
        email: '',
        conName: '',
        conMobile: '',
        conQq: '',
        conEmail: '',
        legalIndentity: '',
        openBank: '',
        obBranch: '',
        status: '',
        compName: '',
        compMobile: '',
        compPhone: '',
        compAddress: '',
        licenseNum: '',
        taxRegistNum: '',
        organNum: '',
        legal: '',
        bankNum: '',
        shopInfo:{
            shopName: ''

        },
        userInfo:{
          userName: '',
          userPassword: ''
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
